import { methods } from './utils/register-route';
import './router/SYS_Teacher';

/**
 *
 * @param router 注册路由
 */
export const routerRegister = (router) => {

	methods.forEach((m) => {
		const prefix = toLine(m.prefix);
		const methodName = m.name.toLocaleLowerCase();
		let url = '/' + prefix + '/' + methodName;
		if (m.name === 'index') {
			url = '/' + prefix + '/';
		}
		if (m.url) {
			if (m.url.charAt(0) !== '/') {
				url = '/' + prefix + '/' + methodName + '/' + m.url;
			} else {
				url = m.url;
			}
		}

		console.log("路径:")
		console.log(url)

		router[m.method](url, m.handler);
	});
};

/**
 * 对参数进行大小写，替换处理
 * @param name
 */
function toLine(name) {
	return name.toLocaleLowerCase();
	// return name.replace(/([A-Z])/g, "_$1").toLocaleLowerCase();
}
